void solve()
{
  int n;
  cin >> n;

  vector<vector<pii>> g(n + 1);
  rep(i, 1, n - 1) {
    int u, v;
    cin >> u >> v;
    g[u].pb({v, 0});
    g[v].pb({u, 1});
  }

  int ret = 0, ans = 0;
  vi dp(n + 1, 0);
  auto dfs = [&](auto &&dfs, int u, int fa, int w, int dep) -> void {
    for (auto &[v, c] : g[u]) {
      if (v != fa) {
        ans += c;
        dfs(dfs, v, u, w + c, dep + 1);
        dp[u] = max(dp[u], dp[v] - (c == 0 ? 1 : -1));
        ret = max(ret, dp[u]);
      }
    }
  };

  int res = n;
  rep(i, 1, n) {
    rep(j, 1, n) {
      dp[j] = 0;
    }
    ret = 0, ans = 0;
    dfs(dfs, i, 0, 0, 0);
    res = min(res, ans - ret);
  }
  cout << res;
}